/**
 * Created by wanghe on 2016/11/25.
 */
var InsertUser = function() {
    this.init();
}

InsertUser.prototype.init = function() {
    $('.btn-ture').click(this.doInsertUser.bind(this));
}

InsertUser.prototype.doInsertUser = function() {
    var username = $('#username').val();
    var password = $('#password').val();
    var nickname = $('#nickname').val();
    var qq = $('#qq').val();
    var email = $('#email').val();
    var phoneNumber = $('#phoneNumber').val();
    if(!username || !password){
        notie.alert(2,"用户名、密码不能为空！",2);
        return;
    }
    $('.btn-ture').button('loading');
    URLHelper.ajax({
        'url': URLHelper.insertuserURL(),
        'method': 'POST',
        'dataType': 'json',
        'data': {
            'username':username,
            'password':password,
            'nickname':nickname,
            'qq':qq,
            'email':email,
            'phoneNumber':phoneNumber
        },
        'success': function(data) {
            $('.btn-ture').button('reset');
            if(data.code==1){
                window.location.href = "/admin/userview";
            }else if(data.code==2){
                notie.alert(2,"用户名已存在！",2);
                return;
            }else{
                notie.alert(3,"添加失败！",2);
                return;
            }
        },
        'error': function(err) {
            console.log(err);
        }
    });
}
